import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

import static org.openqa.selenium.By.name;

public class Login {

    public static String userName = "admin";
    public static String password = "novus";
    public static String fakeUserName = "ggghd";

    private final WebDriver driver;
    public static WebElement loginField, loginFieldd;

    public Login(WebDriver driver) {
        this.driver = driver;
    }

    public void typeUserName() {
        loginField = driver.findElement(By.id(PageVariableValues.loginUserNameField));
        loginField.sendKeys(userName);
    }

    public void typePassword() {
        WebElement passwordField = driver.findElement(By.id(PageVariableValues.loginPasswordField));
        passwordField.sendKeys(password);
    }

    public void clickSignIn(WebDriverWait wait, String destination) {
        WebElement signInButton = driver.findElement(name(PageVariableValues.loginPageButton));
        signInButton.click();
        if(destination != "flash"){
            wait.until(ExpectedConditions.titleIs(destination));
        }else{
            wait.until(ExpectedConditions.visibilityOfElementLocated(By.id(destination)));
        }
    }

    public void typeFakeUserName() {
        loginFieldd = driver.findElement(By.id(PageVariableValues.loginUserNameField));
        loginFieldd.sendKeys(fakeUserName);
    }

}
